package com.st.controller;

import com.st.base.BaseResult;
import com.st.service.BannerService;
import com.st.vo.BannerListVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "轮播图控制器", description = "此控制器管理所有关于轮播图的操作接口")
@RestController
@RequestMapping("banner")
public class BannerController {

    @Resource
    private BannerService bannerService;

    /*
    接口的编写需要考虑的问题：
        1.哪些是业务代码？
        2.需不需要对所依赖对象返回的数据进行判断校验
     */
    @Operation(summary = "获取轮播图列表", description = "根据分页获取轮播图列表，分页参数非必传")
    @Parameters(
            {
                    @Parameter(name = "pageNumber", description = "页码", required = false),
                    @Parameter(name = "pageSize", description = "页容量", required = false)
            }
    )
    @RequestMapping(path = "list", method = RequestMethod.GET)
    public BaseResult<List<BannerListVo>> getBannerList(
            @RequestParam(name = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
            @RequestParam(name = "pageSize", required = false, defaultValue = "5") Integer pageSize
    ) {
        List<BannerListVo> bannerListVos = bannerService.getList();
        if (bannerListVos != null && bannerListVos.size() > 0) {
            return BaseResult.ok(bannerListVos);
        } else {
            return BaseResult.error("暂无数据！");
        }
    }


    @RequestMapping(path = "pageList", method = RequestMethod.GET)
    public BaseResult<List<BannerListVo>> pageList(
            @RequestParam(name = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
            @RequestParam(name = "pageSize", required = false, defaultValue = "5") Integer pageSize
    ) {
        List<BannerListVo> bannerListVos = bannerService.getPageList(pageNumber, pageSize);

        if (bannerListVos != null && bannerListVos.size() > 0) {
            return BaseResult.ok(bannerListVos);
        } else {
            return BaseResult.error("暂无数据！");
        }
    }


}
